package com.egao.common.manage.student;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.exception.BusinessException;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.entity.vo.StudentRecommendVO;
import com.egao.common.module.student.service.StudentRecommendService;
import com.egao.common.module.student.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 学生消息推荐
 * 猜您喜欢
 * @author dl
 */
@Api(tags = "学生消息推荐管理")
@RestController
@RequestMapping("${api}")
public class StudentRecommendController extends BaseController {

    @Autowired
    private StudentRecommendService studentRecommendService;

    @Autowired
    private StudentService studentService;

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("学生消息推荐管理-猜你喜欢")
    @ApiPageParam
    @GetMapping("/student/recommend/page")
    public JsonResult page(HttpServletRequest request) {
        PageParam<StudentRecommendVO> pageParam = new PageParam<>(request);
        // 猜你喜欢
        Student student = studentService.getByUserId(getLoginUserId());
        if (student == null) {
            throw new BusinessException("学生不存在");
        }
        pageParam.put("userId", getLoginUserId());
        return JsonResult.ok().setData(studentRecommendService.getStudentRecommend(pageParam));
    }

}
